<template>
  <div class="preview-area">
    <h4 class="preview-title">预览效果</h4>
    <div class="preview-device-selector">
      <el-radio-group v-model="previewDevice" size="small">
        <el-radio-button label="pc">PC端</el-radio-button>
        <el-radio-button label="mobile">移动端</el-radio-button>
      </el-radio-group>
    </div>
    
    <!-- PC端预览 -->
    <div v-if="previewDevice === 'pc'" class="preview-container pc-preview">
      <div class="package-card">
        <div class="package-tag" v-if="packageForm.activate_name">{{ packageForm.activate_name }}</div>
        <div class="package-title">
          <template v-if="packageForm.title.trim()">【{{ packageForm.title }}】</template> 
          {{ vipName }} {{ systemName }}
        </div>
        <div class="package-price">
          <span class="current-price">¥{{ previewPrice }}</span>
          <span class="original-price" v-if="packageForm.origin_price">¥{{ packageForm.origin_price }}</span>
        </div>
        <div class="package-desc">
          <div v-if="packageForm.tag">{{ packageForm.tag }}</div>
          <div>{{ `${packageForm.day}天` }}</div>
        </div>
        <button class="package-button active">立即购买</button>
      </div>
    </div>
    
    <!-- 移动端预览 -->
    <div v-else class="preview-container mobile-preview">
      <div class="mobile-package-card">
        <div class="mobile-package-content">
          <div class="mobile-package-title">
            <span><template v-if="packageForm.title.trim()">【{{ packageForm.title }}】</template> {{ vipName.toLowerCase() }} {{ systemName }}</span>
            <span class="mobile-day">{{ packageForm.day }}天</span>
          </div>
          <div class="mobile-package-promotion" v-if="packageForm.activate_name">
            <span class="mobile-promotion-tag">{{ packageForm.activate_name }}</span>
          </div>
          <div class="mobile-package-price">
            <div class="mobile-price-main">
              <span class="mobile-price-origin" v-if="packageForm.origin_price">¥{{ packageForm.origin_price }}</span>
              <span class="mobile-price-current">¥{{ previewPrice }}起</span>
            </div>
            <div class="mobile-price-daily">
              <span>¥{{ previewPrice.toFixed(2) }}/天</span>
            </div>
          </div>
          <div class="mobile-package-tag" v-if="packageForm.tag">
            {{ packageForm.tag }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'

const props = defineProps({
  packageForm: {
    type: Object,
    required: true
  },
  vipName: {
    type: String,
    required: true
  },
  systemName: {
    type: String,
    required: true
  }
})

const previewDevice = ref('pc')

// 计算预览价格
const previewPrice = computed(() => {
  if (props.packageForm.price_tiers.length === 0) return 0
  
  // 显示最低的价格梯度
  const prices = props.packageForm.price_tiers.map((tier: any) => tier.price)
  return Math.min(...prices)
})
</script>

<style lang="scss" scoped>
.preview-area {
  flex: 1;
  border-left: 1px dashed var(--el-border-color);
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  
  .preview-title {
    margin-top: 0;
    margin-bottom: 15px;
    font-weight: 500;
    color: var(--el-text-color-primary);
  }
  
  .preview-device-selector {
    margin-bottom: 20px;
  }
  
  .preview-container {
    padding: 15px;
    background-color: #f5f7fa;
    border-radius: 8px;
    
    &.pc-preview {
      .package-card {
        width: 200px;
        padding: 15px;
        border-radius: 8px;
        border: 1px solid #e4e7ed;
        background-color: #fff;
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
        position: relative;
        transition: all 0.3s;
        cursor: pointer;
        
        &:hover {
          box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.1);
        }
        
        .package-tag {
          position: absolute;
          top: 0;
          right: 0;
          background-color: #e6a23c;
          color: #fff;
          padding: 2px 8px;
          font-size: 12px;
          border-radius: 0 8px 0 8px;
        }
        
        .package-title {
          font-size: 14px;
          font-weight: bold;
          margin-bottom: 10px;
          color: #303133;
        }
        
        .package-price {
          margin-bottom: 10px;
          
          .current-price {
            font-size: 20px;
            font-weight: bold;
            color: #f56c6c;
          }
          
          .original-price {
            font-size: 14px;
            color: #909399;
            text-decoration: line-through;
            margin-left: 5px;
          }
        }
        
        .package-desc {
          font-size: 12px;
          color: #606266;
          margin-bottom: 15px;
          min-height: 36px;
        }
        
        .package-button {
          width: 100%;
          padding: 8px 0;
          border: none;
          border-radius: 4px;
          background-color: #f5f7fa;
          color: #606266;
          cursor: pointer;
          transition: all 0.3s;
          
          &:hover, &.active {
            background-color: #409eff;
            color: #fff;
          }
        }
      }
    }
    
    &.mobile-preview {
      .mobile-package-card {
        width: 100%;
        background-color: #fff;
        border-radius: 12px;
        overflow: hidden;
        border: 2px solid #f56c6c;
        box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.1);
        
        .mobile-package-content {
          padding: 15px;
          
          .mobile-package-title {
            display: flex;
            justify-content: flex-start;
            align-items: center;
            margin-bottom: 8px;
            
            span {
              font-size: 16px;
              font-weight: 500;
              color: #303133;
            }
            
            .mobile-day {
              margin-left: 5px;
            }
          }
          
          .mobile-package-promotion {
            margin-bottom: 8px;
            
            .mobile-promotion-tag {
              display: inline-block;
              background-color: #f56c6c;
              color: #fff;
              padding: 2px 8px;
              font-size: 12px;
              border-radius: 4px;
            }
          }
          
          .mobile-package-price {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 8px;
            
            .mobile-price-main {
              .mobile-price-origin {
                font-size: 14px;
                color: #909399;
                text-decoration: line-through;
                margin-right: 5px;
              }
              
              .mobile-price-current {
                font-size: 18px;
                font-weight: bold;
                color: #f56c6c;
              }
            }
            
            .mobile-price-daily {
              font-size: 14px;
              color: #606266;
            }
          }
          
          .mobile-package-tag {
            font-size: 12px;
            color: #606266;
          }
        }
      }
    }
  }
}
</style> 